// @author: caoshi
// @date: 2021-05-21 21:44
package util

import (
	"fmt"
	"github.com/jmoiron/sqlx"
)

// 数据库连接驱动和连接参数
const (
	driver         string = "mysql"
	dataSourceName string = "root:hadoop123@tcp(121.196.166.188:3306)/devtest"
)

// 获取数据库连接对象
func GetDB() (*sqlx.DB, error) {
	dbx, err := sqlx.Open(driver, dataSourceName)
	if err != nil {
		fmt.Println("连接数据库失败", err)
		return nil, err
	}
	return dbx, nil
}

func GetDBSqlx() (*sqlx.DB, error) {
	dbx, err := sqlx.Open(driver, dataSourceName)
	if err != nil {
		fmt.Println("连接数据库失败", err)
		return nil, err
	}
	return dbx, nil
}
